<template>
  <!-- tab选项卡 -->
  <div class="tab">
    <div
      class="tab-item"
      v-for="(item, index) in titles"
      :key="index"
      @click="TabClink(index)"
      :class="{ active: index == currentIndex }"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
import { ref } from "@vue/reactivity";
export default {
  //接受父组件传来的titles
  props: {
    titles: {
      type: Array,
    },
  },
  setup(props, { emit }) {
    let currentIndex = ref(0);

    const TabClink = (index) => {
      currentIndex.value = index;
      emit("tabClick", index);
    };
    return {
      TabClink,
      currentIndex,
    };
  },
};
</script>
  
<style lang="scss" scoped>
.tab {
  height: 45px;
  display: flex;
  line-height: 45px;
  text-align: center;
  position: sticky;
  top: 44px;
  z-index: 9999;
  background: #ffffff;
  .tab-item {
    flex: 1;

    span {
      padding: 10px;
    }
  }
  .active {
    color: var(--color-tint);
    border-bottom: 2px solid var(--color-tint);
  }
}
</style>


